define(function(require, exports, module) {
	var List = require('../util/list');
	var $ = require('jquery');
	require('jbox');
	require('jquery/jquery-form/1.0.0/jquery.form.js');
	require('jquery/jquery-json/2.4.0/jquery.json.js');
	require('artTemplate/artTemplate/2.0.1/template.js');
	

	$('#fund-tab a').click(function(e) {
		e.preventDefault();
		$(this).tab('show');
	});
	exports.options = {
		listLink : '',
		listParams : '',
		pageLink : '',
		pageParams : ''
	};

	uid = $g_user.id;
	// 将全剧变量中的用户名放到#suppliment_user元素中
	$('.suppliment_user').append($g_user.name);
	// 资助管理
	var management = new List();
	management.options.template = "order-management-template";
	management.options.container = "#order-management";
	management.options.links = {
		"list" : $CONFIG.base_url + '/api/project/support/user/list'
	};
	management.options.params = {
		"uid" : uid,
		"p" : 1,
		"s" : 5
	};
	management.load();
	// 收支明细
	exports.fundDetailTitle = function fundDetailTitle(date) {
		var fundDetailTitle = new List();
		fundDetailTitle.options.template = "fund-title-template";
		fundDetailTitle.options.container = "#fund-title";
		fundDetailTitle.options.links = {
			"list" : $CONFIG.base_url + '/api/fund_detail/period/list'
		};
		fundDetailTitle.options.params = {
			"uid" : uid,
			"days" : date,
			"p" : 1,
			"s" : 25
		};
		fundDetailTitle.load(function(){
			exports.getUserInfo();
		});
	};

	exports.detail = function detail(date) {
		var fundDetails = new List();
		fundDetails.options.template = "fund-table-template";
		fundDetails.options.container = "#fund-table";
		fundDetails.options.links = {
			"list" : $CONFIG.base_url + '/api/fund_detail/period/list'
		};
		fundDetails.options.params = {
			"uid" : uid,
			"days" : date,
			"p" : 1,
			"s" : 10
		};
		fundDetails.load();
	};
	exports.fundDetailTitle(15);
	exports.detail(15);
/*	$('#days').change(function() {
		var days = $("#days").find('option:selected').val();
		exports.fundDetailTitle(days);
		exports.detail(days);
});*/

	// 账户充值
	$('#rechange').click(function(e) {
		//$this = $("#deposit");
		e.preventDefault();
		var postData = $.toJSON(form2js('deposit', '.', true));
		//console.log(postData);
		//$.jBox.info('Hello jBox', '提示');
		$.ajax({
			url : $CONFIG.base_url+ "/api/fund_detail/web/deposit",
			type : "POST",
			data : postData,
			contentType : "application/json",
			success : function(data) {
				//$.jBox.info('正在充值...', '提示');
				//data.total_fee = data.total_fee/100;//测试成功后请删除
				//console.log(data);
				//console.log(data.sHtmlText);
				$("#deposit").append(data.sHtmlText);
			},
			error : function() {
			}
		});
	});
	$("#custom").on("click",function(){
		$("#optionsRadios7").click();
	});
	
	$("#custom").keyup(function(){
		exports.checkCustomKeyup("custom");
    }).bind("paste",function(){  //CTR+V事件处理 
    	exports.checkCustom("custom");
    }).blur(function(){
    	exports.checkCustom("custom");
    });
	
	exports.checkCustom = function(id){
		var element=$("#"+id);
		element.val(element.val().replace(/\D|^0/g,''));
		if(element.val().trim()==""){
			element.val(1);
		}else if(parseInt(element.val())==0){
			element.val(1);
		}
		$(element).val(parseInt($(element).val()));
	};
	
	exports.checkCustomKeyup = function(id){
		var element=$("#"+id);
		element.val(element.val().replace(/\D|^0/g,''));
		if(element.val().trim()==""){
			return;
		}else if(parseInt(element.val())==0){
			element.val(1);
		}
		$(element).val(parseInt($(element).val()));
	};
	
	
	
	//获取用户积善值
	exports.getUserInfo=function(){
		exports.options.getUserInfLink=$CONFIG.base_url+"/api/user";
		exports.options.getUserInfParams={"uid":$g_user.id};
		var userList=$.get(exports.options.getUserInfLink,exports.options.getUserInfParams);
		userList.done(function(data){
			$("#userBalance0").text(parseFloat(data.user.fund).toFixed(2));
			$("#userBalance1").text(parseFloat(data.user.fund).toFixed(2));
			$("#userBalance2").text(parseFloat(data.user.fund).toFixed(2));
		});
	};
	$(".cash-type").click(function(){
		if($(this).val()=="1"){
			$(".input-type").attr("placeholder","请输入银行账号");
			$(".bank-name").show();
			$(".bank-input").show();
			$(".pay-type").val("1");
		}else if($(this).val()=="0"){
			$(".input-type").attr("placeholder","请输入支付宝账号");
			$(".bank-name").hide();
			$(".bank-input").hide();
			$(".pay-type").val("0");
		}
	});
/*	exports.getLast=function(){
		var getting=$.get($CONFIG.base_url+"/api/admin/getLatestCash",{uid:uid});
		getting.done(function(data){
			if(data.payType=="1"){
				$(".cash-bank").attr("checked","checked");
				$(".bank-name").show();
				$(".bank-input").show();
			}
			$(".rel-name").val(data.realName);
			$(".rel-phone").val(data.phone);
			$(".rel-pay").val(data.account);
			
		}).fail(function(){
			$.jBox.tip("获取上次提现信息失败！");
		});
	};
	exports.getLast();*/
	//提交提现申请
	$("#getcash-button").click(function(){
		var value=false;
		var hasGet=$.get($CONFIG.base_url+"/api/fund_detail/getApplication",{uid:uid});
		hasGet.done(function(data){
			if(data!=""){
				value=true;
			};	
		if(value==true){
			$.jBox.tip("上次的提现申请正在审核,审核通过后再重试！");
			return;
		}else{
			var formData=$("#getcash-form").serialize();
			console.log(formData);
			var getting=$.get($CONFIG.base_url+"/api/fund_detail/getCash",formData);
			getting.done(function(){
				$.jBox.tip("提现申请已经提交！我们会在2~3个工作日内处理，请注意查收！");
				window.location.href=$CONFIG.base_url+"/fund";
			});
		};
	});
	});
});